package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusWarehoseInfo;
import com.drug.wms.service.IBusWarehoseInfoService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库信息Controller
 *
 * @author ruoyi
 * @date 2021-11-15
 */
@RestController
@RequestMapping("/wms/warehouse")
@Api(description = "仓库信息")
public class BusWarehoseInfoController extends BaseController {
    @Autowired
    private IBusWarehoseInfoService busWarehoseInfoService;

    /**
     * 查询仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询仓库信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseName", value = "仓库名称", dataType = "String", dataTypeClass = String.class),
    })
    public TableDataInfo list(BusWarehoseInfo busWarehoseInfo) {
        startPage();
        PageHelper.orderBy("create_time desc");
        List<BusWarehoseInfo> list = busWarehoseInfoService.selectBusWarehoseInfoList(busWarehoseInfo);
        return getDataTable(list);
    }

    /**
     * 导出仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "仓库信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusWarehoseInfo busWarehoseInfo) {
        List<BusWarehoseInfo> list = busWarehoseInfoService.selectBusWarehoseInfoList(busWarehoseInfo);
        ExcelUtil<BusWarehoseInfo> util = new ExcelUtil<BusWarehoseInfo>(BusWarehoseInfo.class);
        return util.exportExcel(list, "仓库信息数据");
    }

    /**
     * 获取仓库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "仓库id", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @ApiOperation("获取仓库信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busWarehoseInfoService.selectBusWarehoseInfoById(id));
    }

    /**
     * 新增仓库信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "仓库信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseName", value = "仓库名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "warehouseTypeCode", value = "仓库类型编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "warehouseNatureCode", value = "仓库性质编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "positionManagemeCode", value = "货位管理方式编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "useStatusCode", value = "使用状态编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "connectPhone", value = "联系电话", dataType = "String", dataTypeClass = String.class)
    })
    @ApiOperation("新增仓库信息")
    public AjaxResult add(@RequestBody BusWarehoseInfo busWarehoseInfo) {
        return toAjax(busWarehoseInfoService.insertBusWarehoseInfo(busWarehoseInfo));
    }

    /**
     * 修改仓库信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "仓库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "仓库id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "warehouseName", value = "仓库名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "warehouseTypeCode", value = "仓库类型编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "warehouseNatureCode", value = "仓库性质编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "positionManagemeCode", value = "货位管理方式编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "useStatusCode", value = "使用状态编码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "connectPhone", value = "联系电话", dataType = "String", dataTypeClass = String.class)
    })
    @ApiOperation("修改仓库信息")
    public AjaxResult edit(@RequestBody BusWarehoseInfo busWarehoseInfo) {
        return toAjax(busWarehoseInfoService.updateBusWarehoseInfo(busWarehoseInfo));
    }

    /**
     * 删除仓库信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "仓库信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除仓库信息")
    @ApiImplicitParam(name = "ids", value = "仓库ids", required = true,allowMultiple = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busWarehoseInfoService.deleteBusWarehoseInfoByIds(ids));
    }
}
